package fr.emse.tatiana.cordtravisualisation;

import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;

import fr.emse.tatiana.graphical.DisplayRule;
import fr.emse.tatiana.replayable.IReplayableModel;


public class CordtraPartFactory implements EditPartFactory {

	private Map<Object,EditPart> objectmap;
	private List<CordtraRule> rules;
	private List<Boolean> show;
	
	public CordtraPartFactory(List<CordtraRule> rules2, List<Boolean> show) {
		super();
		objectmap = new Hashtable<Object, EditPart>();
		this.rules = rules2;
		this.show = show;
	}

	public EditPart createEditPart(EditPart context, Object model) {

		AbstractGraphicalEditPart part = null; 

		if (objectmap.containsKey(model)) {
			return objectmap.get(model);
		}

		if (model instanceof IReplayableModel) {
			part = new CordtraReplayableModelPart((IReplayableModel) model, show);
		} else {
			part = new FacetPart((ReplayableFacet) model, rules);
		} 

		part.setParent(context);
		objectmap.put(model,part);

		return part;
	}

	public EditPart getEditPart(Object model) {
		return objectmap.get(model);
	}

}
